package cn.edu.lingnan.translation.controller;

import cn.edu.lingnan.translation.service.AdminService;
import cn.edu.lingnan.translation.service.UserService;
import cn.edu.lingnan.translation.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName StatisticsController
 * @Author BAO
 * @Description 统计接口
 * @Date 2020/10/17 21:03
 * @Version 1.0
 */
@RestController
@RequestMapping("/statistics")
public class StatisticsController {
    @Autowired
    private UserService userService;
    @Autowired
    private AdminService adminService;

    @ApiOperation(value = "获取统计数据")
    @GetMapping("/getCount")
    public R getCount() {
        int userCount = userService.count(null);
        int adminCount = adminService.count(null);
        Map<String, Integer> count =  new HashMap<>();
        count.put("user", userCount);
        count.put("admin", adminCount);
        return R.ok().data("countList", count);
    }



}
